package com.woniu.presell.controller;

import com.alibaba.fastjson.JSON;
import com.woniu.common.util.Result;
import com.woniu.presell.VO.LicenceVO;
import com.woniu.presell.entity.Check;
import com.woniu.presell.service.CheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @program: house-after
 * @description:
 * @author: qqq
 * @create: 2022-12-15 20:22
 **/
@RestController
@RequestMapping("pcheck")
public class CheckController {
    @Autowired
    private CheckService checkService;
    @PostMapping("update")
    public Result update(@RequestBody Map<String,Object> map){
        String checkForm = JSON.toJSONString(map.get("checkForm"));
        Check recrod = JSON.parseObject(checkForm, Check.class);
        checkService.updateSelcvite(recrod);
        String allForm = JSON.toJSONString(map.get("allForm"));
        LicenceVO licenceVO = JSON.parseObject(allForm, LicenceVO.class);
        int i = checkService.licenceUpdate(licenceVO.getLicenceId());
        if(i>0){
            return Result.ok("修改成功").data("check",recrod);
        }else{
            return Result.error("失败请重试");
        }
    }
    @GetMapping("queryId/{id}")
    public Result queryId(@PathVariable("id") Long id){
        Check check = checkService.selectById(id);
        if(check!=null){
            return Result.ok("查询成功").data("check",check);
        }else{
            return Result.error("失败请重试");
        }
    }
}
